<template>
  <div> 
    <TableTitle><p>扫码区域</p></TableTitle>
    <div style="margin:2px 3px">
        <span>条码：</span><el-input v-model="searchData.barcode" style="width:500px" size="mini" placeholder="扫码区域" @change="scanQuery"></el-input>
    </div>
    <!--查询区域-->
    <TableTitle><p>日计划物料配套信息表</p></TableTitle>
    <div>
      <el-form :inline="true" :model="searchData" label-width="120px" class="demo-form-inline">
          <el-form-item label="AO编码:">
              <el-input v-model="searchData.aoCode" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="工作包编码:">
              <el-input v-model="searchData.packageCode" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="图号:">
              <el-input v-model="searchData.itemCode" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="质量编号:">
              <el-input v-model="searchData.qualityCode" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="型号:">
              <el-input v-model="searchData.mProductNumber" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="机型:">
              <el-input v-model="searchData.productCode" class="el-form-input" size="mini" placeholder="10403"></el-input>
          </el-form-item>
          <el-form-item label="批次:">
              <el-input v-model="searchData.batchNo" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="起始架次:">
              <el-input v-model="searchData.startPlaneNo" class="el-form-input" size="mini" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="日计划开始时间">
              <el-date-picker size="mini" class="el-form-input" v-model="searchData.dailyStartTime" type="date" placeholder="选择日期" 
              value-format="yyyy-MM-dd" ></el-date-picker>
          </el-form-item>
          <el-form-item label="日计划结束时间">
              <el-date-picker size="mini" class="el-form-input" v-model="searchData.dailyEndTime" type="date" placeholder="选择日期" 
              value-format="yyyy-MM-dd" ></el-date-picker>
          </el-form-item>
      </el-form>
      <div style="text-align: center;margin-bottom:3px">
          <el-button type="primary" size="mini" @click="smSpmSearch">查询</el-button>
          <el-button type="primary" size="mini" @click="doReset">重置</el-button>
          <el-button type="primary" size="mini" @click="direDispatch">直配</el-button>
      </div>
    </div>
    <div class="em-spm-topTable">
      <el-table ref="receiveTable" size="mini" :data="resData" style="width: 100%" height="300"
       highlight-current-row  @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="40"> </el-table-column>
      <el-table-column type="index" label="序号" width="50"> </el-table-column>
      <!-- <el-table-column prop="monthTime" label="月计划" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="weekTime" label="周计划" width="170" :show-overflow-tooltip="true"> </el-table-column> -->
      <el-table-column prop="dailyTime" label="日计划时间" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="itemCode" label="物料编码" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="qualityCode" label="质量编号/件号" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="startPlaneNo" label="架次" width="50" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="batchNo" label="批次" width="50" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="productCode" label="机型" width="80" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="aoCode" label="AO编码" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="packageCode" label="工作包编码" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="itemQty" label="需求数量" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="allreadyPackageCount" label="已经分拣数量" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="barcode" label="条码" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="isSort" label="是否分拣" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="state" label="配套状态" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="deliveryState" label="配送状态" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="creationDate" label="配套时间" width="170" :show-overflow-tooltip="true"> </el-table-column>
      
      <el-table-column prop="deliveryEmpCode" label="配送人" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="deliveryTime" label="配送时间" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="artChangeType" label="工艺更改类型" width="100" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="toolCode" label="托盘号" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="repartAss" label="装配图号" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="itemName" label="物料名称" width="150" :show-overflow-tooltip="true" > </el-table-column>
      <el-table-column prop="itemType" label="物料类型" width="150" :show-overflow-tooltip="true" > </el-table-column>
      <el-table-column prop="mesCheckQualiticationId" label="合格证" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="wmsDeliveryPlanId" label="交接单ID" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="wmsItemInventoryId" label="台账ID" width="170" :show-overflow-tooltip="true"> </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNumber"
      :page-sizes="[10,20,50,100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount">
    </el-pagination>
    
  </div>

  
</template>
<script>
import TableTitle from "../../../../../components/TableTitle.vue";
import { directDeliveryData } from "@/utils/api.js";
import request from "@/utils/request.js";

export default {
  name: "MdRddTopTable",
  components: { TableTitle},
  data() {
    return{
            searchData:{//查询参数
                "productCode":"",
                "aoCode":"",
                "packageCode":"",
                "itemCode":"",
                "qualityCode":"",
                "mProductNumber":"",
                "batchNo":"",
                "startPlaneNo":"",
                "isSort":"",
                "state":"",
                "deliveryState":"",
                "monthStartTime":"",
                "monthEndTime":"",
                "weekStartTime":"",
                "weekEndTime":"",
                "dailyStartTime":"",
                "dailyEndTime":"",
                "barcode":""
            },
             // 当前页数
            pageNumber: 1,
            // 数据总个数
            totalCount: 0,
            // 返回的数据数组
            resData: [],
            // 每页数据个数
            pageSize: 20,
            // 确认列表高亮参数
            stableIndex: 0,
            //选择事件参数
            selectData:[],
            // 接收Top传来的数据--用于查表
            topLastInfo:'',
            isSortStatus: [
                {
                value: "Y",
                label: "已分拣",
                },
                {
                value: "N",
                label: "未分拣",
                },
                {
                value: "",
                label: "所有",
                },
            ],
            deliveryStatus:[
                {
                value: "02",
                label: "已配送",
                },
                {
                value: "00",
                label: "未配送",
                },
                {
                value: "04",
                label: "已移交",
                },
                {
                value: "06",
                label: "已接收",
                },
                {
                value: "",
                label: "所有",
                },
            ],
            stateStatus: [
                {
                value: "02",
                label: "已配套",
                },
                {
                value: "00",
                label: "未配套",
                },
                {
                value: "04",
                label: "部分配套",
                },
                {
                value: "01",
                label: "无库存",
                },
                {
                value: "",
                label: "所有",
                },
            ],
        }
  },
  methods: {
    //直配按钮
    direDispatch(){
        if(this.selectData.length==0){
                this.$Alert({title: "失败",message:"请至少选择一条数据",type: "error"});
                return;
        }
        //调用执行分拣命令创建操作
        request.post("/DirectDeliveryRest/directDelivery",this.selectData).then((res)=>{
            if(res.data.retCode=="200"){
                this.$Alert({title: "成功", message: res.data.message,type: "success"});
                return ;
            }else{
                this.$Alert({title: "失败", message: res.data.message,type: "error"});
                return ;
            }
        })
    },
    //重置
    doReset(){
        Object.assign(this.searchData,this.$options.data().searchData);
    },
    // 勾选表格函数
    handleSelectionChange(val) {
        this.selectData = val;
    },
    // 分页---每页数据条数---传给TopSearch
    handleSizeChange(val){
      this.pageSize = val;
      directDeliveryData({
            searchParams:{
                productCode:this.searchData.productCode,
                batchNo:this.searchData.batchNo,
                startPlaneNo:this.searchData.startPlaneNo,
                dailyStartTime:this.searchData.dailyStartTime,
                dailyEndTime:this.searchData.dailyEndTime,
                aoCode:this.searchData.aoCode,
                packageCode:this.searchData.packageCode,
                itemCode:this.searchData.itemCode,
                qualityCode:this.searchData.qualityCode,
                mProductNumber:this.searchData.mProductNumber,
                barcode:this.searchData.barcode
            },
          pageParameter: {
              rows: this.pageSize,
              page: this.pageNumber
          },
        }).then((res) => {
            console.log('分拣预配套Last表',res)
            this.resData = res.data.responseBody.result;
            this.totalCount = res.data.responseBody.pageParameter.totalCount;
      });
    },
    // 分页---页数---传给TopSearch
    handleCurrentChange(val) {
        this.pageNumber = val;
        directDeliveryData({
            searchParams:{
                productCode:this.searchData.productCode,
                batchNo:this.searchData.batchNo,
                startPlaneNo:this.searchData.startPlaneNo,
                dailyStartTime:this.searchData.dailyStartTime,
                dailyEndTime:this.searchData.dailyEndTime,
                aoCode:this.searchData.aoCode,
                packageCode:this.searchData.packageCode,
                itemCode:this.searchData.itemCode,
                qualityCode:this.searchData.qualityCode,
                mProductNumber:this.searchData.mProductNumber,
                barcode:this.searchData.barcode
            },
            pageParameter: {
                rows: this.pageSize,
                page: this.pageNumber
            },
            }).then((res) => {
                console.log('分拣预配套Last表',res)
                this.resData = res.data.responseBody.result;
                this.totalCount = res.data.responseBody.pageParameter.totalCount;
            });
    },
    smSpmSearch(){
      directDeliveryData({
            searchParams:{
                productCode:this.searchData.productCode,
                batchNo:this.searchData.batchNo,
                startPlaneNo:this.searchData.startPlaneNo,
                dailyStartTime:this.searchData.dailyStartTime,
                dailyEndTime:this.searchData.dailyEndTime,
                aoCode:this.searchData.aoCode,
                packageCode:this.searchData.packageCode,
                itemCode:this.searchData.itemCode,
                qualityCode:this.searchData.qualityCode,
                mProductNumber:this.searchData.mProductNumber,
                barcode:this.searchData.barcode
            },
            pageParameter:{
                rows:this.pageSize,
                page:this.pageNumber
            }
        }).then((res)=>{
            if(res.data.retCode == 200){
              //  this.resData = res.xxx
                this.resData = res.data.responseBody.result
                this.totalCount = res.data.responseBody.pageParameter.totalCount
            }
        })
    },
    scanQuery(){
        var newbarcode = this.searchData.barcode;
        if(newbarcode.includes('"CPHGZ"')){//成品扫码处理
            this.barcode = JSON.parse(newbarcode).CPHGZ;
        }else if(newbarcode.includes('"CKCODE"')){//标准件扫码处理
            this.barcode = JSON.parse(newbarcode).CKCODE;
        }
        this.$options.methods.smSpmSearch.bind(this)();
    }
    
  },
  mounted() {
    directDeliveryData({
            searchParams:{
                // msTaskAoId:this.topLastInfo
            },
            pageParameter: {
                rows: this.pageSize,
                page: this.pageNumber
            },
        }).then((res) => {
            this.resData = res.data.responseBody.result;
            this.totalCount = res.data.responseBody.pageParameter.totalCount;
        });
  },
};
</script>
<style scoped>
.md-rdd-topTable {
  width: 100%;
  height: 100%;
  text-align: center;
}
.el-form-input{
    width:150px
}
.em-spm-topTable {
    text-align: center;
}
.el-form-item{
    margin-bottom:0px !important;
}
</style>